package com.heima.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Description: 定时任务
 * Author: Wzh
 * Date: 2024/8/6
 */
@Component
@Slf4j
public class XxlJobTask {
    @Value("${xxl.job.executor.port}")
    private int port;

    @XxlJob(value = "demoJobHandler")
    public void task01(){
        int index = XxlJobHelper.getShardIndex();//当前节点的索引
        int total = XxlJobHelper.getShardTotal();//总节点个数

        //模拟10次任务
        for (int i = 1; i <= 10; i++) {
            if (i%total==index){
                System.out.println(port+"执行了一次任务---------"+"第"+i+"次任务执行了");
            }
        }
    }
}

